package com.itjeffrey.autocode.postProcessor;

import org.springframework.beans.BeansException;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.ConstructorArgumentValues;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.stereotype.Component;

/**
 * Bean工厂后置处理器
 * @From: Jeffrey
 * @Date: 2021/3/27
 */
@Component
public class MyBeanFactoryPostProcessor implements BeanFactoryPostProcessor {

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        GenericBeanDefinition beanDefinition = (GenericBeanDefinition)beanFactory.getBeanDefinition("aDemo");

        //设置实例化的构造器
//        ConstructorArgumentValues values = new ConstructorArgumentValues();
//        values.addIndexedArgumentValue(0, "测试");
//        beanDefinition.setConstructorArgumentValues(values);

        //设置属性
//        MutablePropertyValues propertyValues = new MutablePropertyValues();
//        propertyValues.addPropertyValue("bDemo", new BDemo());
//        beanDefinition.setPropertyValues(propertyValues);

        //设置自动注入的类型
//        beanDefinition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_NAME);
    }
}